package 复习泛型;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * 如果一个接口继承了另外一个接口，那么如果实现这个子接口时，需要将它的父类接口里面的方法也实现
 */
public class Test implements B{

    @Override
    public void func1() {

    }

    @Override
    public void func() {

    }
}
interface A{
    public void func();
}
interface B extends A{
    public void func1();
}
class C {
    public static void main3(String[] args) {
        int[]array={2,1,2,3,4,1};
        array=singleNumber1(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main2(String[] args) {
        int a=1234;
        System.out.println(a+"");

        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append(a);
        stringBuilder.append(3.14);
        System.out.println(stringBuilder);
    }
    public static void main1(String[] args) {
        Integer a=1000;
        Integer b=1000;
        boolean p=a==b;
        int c=b.intValue();

    }
    //找出只出现一次的数
    public int singleNumber(int[] nums) {
        //一次确定每一个二进制位
        int sum=0;
        int p=0;
        for (int i = 0; i < 32; i++) {
            sum=0;
            for (int j = 0; j < nums.length; j++) {
                sum=sum+nums[j]>>i&1;
            }
            //求出它的每一位
            if(sum%3!=0) {
                p |= (1 << i);
            }
        }
        return p;
    }
    public static int[] singleNumber1(int[] nums) {
        //找出两个只出现一次的数
        //通过异或
        //记录第一个
        int p1=0;
        //记录第二个
        int p2=0;
        int sum=0;
        for (int i = 0; i < nums.length; i++) {
            sum^=nums[i];
        }
        int count=0;//记录位移几次
        while ((sum&1)==0) {
            sum>>=1;
            count++;
        }
        for (int i = 0; i < nums.length; i++) {
            if((nums[i]>>count&1)==1){
                p1^=nums[i];
            }else {
                p2^=nums[i];
            }
        }
        return new int[]{p1,p2};
    }
}
class Alg{
    public static <E extends Comparable<E>> E funcMax(E[] array ) {
        E max=array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i])<0) {
                max=array[i];
            }
        }
        return max;
    }
}
class C1 {
    public static void main1(String[] args) {
        Integer[]array={1,234,63,21,33,355};
        System.out.println(Alg.funcMax(array));
    }

    public static void main2(String[] args) {
        int[]array={2,8,1,4,6,4};
        System.out.println(maxProfit(array));
    }

    public static void main3(String[] args) {
        int[][]mat = {{1,2},{3,4}};
        mat=matrixReshape(mat,2,4);
        System.out.println("========");
        }

    public static void main(String[] args) {
        Pascal(5);
        System.out.println("========");
        ArrayList <Integer> arrayList=new ArrayList<>();
        arrayList.add(1);

    }
    public static int maxProfit(int prices[]) {
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 0; i <prices.length ; i++) {
            if(min>prices[i]) {
                min=prices[i];
            }else if(prices[i]-min>max) {
                max=prices[i]-min;
            }
        }
        return max;
    }
    public static int[][] matrixReshape(int[][] mat, int r, int c) {

        int size=mat.length*mat[0].length;
        c=size/r;
        int[][]array= new int[r][c];
        //优先保证行都存在
        int x=0;//矩阵的横纵坐标
        int y=0;

        for (int i = 0; i < mat.length ; i++) {
            for (int j = 0; j < mat[0].length ; j++) {
                array[x][y]=mat[i][j];
                y++;
                if(y==c) {
                    x++;
                    y=0;
                }
            }
        }
        return array;
    }
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list=new LinkedList<>();
        List<Integer> p=new LinkedList<>();
        p.add(1);
        list.add(p);
        for (int i = 1; i < numRows; i++) {
            List<Integer> p1=new LinkedList<>();
            p1.add(1);
            for (int j = 1; j < i; j++) {
                int z1= list.get(i-1).get(j);
                int z2= list.get(i-1).get(j-1);
                p1.add(z1+z2);
            }
            p1.add(1);
            list.add(p1);
        }
    return list;
    }
    public static void Pascal1(int x) {
        //杨辉三角的打印
        //用 m n 代替吧
        //用二维数组
        int[][]array=new int[x][x];
        int j=0;
        int i=0;
        for ( i = 0; i < x; i++) {
      /*      for (int k = 0; k < x-i-1; k++) {
                System.out.print(" ");
            }*/
            array[i][0]=1;
            System.out.print(array[i][0]+" ");
            for ( j = 1; j < i; j++) {
                array[i][j]=array[i-1][j-1]+array[i-1][j];
                System.out.print(array[i][j]+" ");
            }
            if(i!=0) {
                array[i][j] = 1;
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }

    }
    public static void Pascal(int x) {
        int[][]array=new int[x][x];
        int i=0;
        int j=0;
        for ( i = 0; i < x; i++) {
            for ( j = 0; j <=i ; j++) {
                if(j==0||i==j) {
                    array[i][j]=1;
                }else {
                    array[i][j]=array[i-1][j-1]+array[i-1][j];
                }
            }
        }
    }

    }
